<!--# layout("/common/layout.html",{"jsBase":"/js/coop/examPapers/"}){ -->

<form class="layui-form layui-form-pane" id="addForm" enctype="multipart/form-data" lay-filter="editform">
    <input type="hidden" name="examId" id="examId">

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">试卷名称</label>
                <div class="layui-input-inline" style="width:512px">
                    <input type="text" name="examTitle" id="examTitle" autocomplete="off" maxlength="80"
                           class="layui-input" lay-verify="required">
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">科目</label>
                <div class="layui-input-inline">
                    <layui:simpleDataSelect name="subjectId" value="${has(examPapers)?examPapers.subjectId:'19'}"
                                            data="${subjectIdList}"
                                            attrId="dictId" attrName="dictValue" laySearch="true"/>
                </div>
            </div>
        </div>
    </div>
    <layui:singleFile id="examUrl" tagName="试卷文件" tips="10M内pdf格式文件"/>

    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">可用标记</label>
                <div class="layui-input-inline">
                    <input type="radio" name="examStatus" value="1" title="可用" checked>
                    <input type="radio" name="examStatus" value="2" title="预备开放">

                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">开放日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="expectDate" id="expectDate" autocomplete="off"
                           class="layui-input input-date">
                </div>
            </div>
        </div>
    </div>
    <layui:submitButtons id="addButton"/>
</form>
<!--#} -->
<script>
    layui.extend({
        loading: '../../../plugins/layui_extends/loading/loading',
    }).define(['form', 'laydate', 'table','loading','examPapersApi'], function (exports) {
        var form = layui.form;
        var examPapersApi = layui.examPapersApi;
        var index = layui.index;
        var isNew = true;
        <!--# if(!(isEmpty(examPapersJson))){  -->
        isNew = false;
        <!--# } -->
        var view = {
            init: function () {
                Lib.initGenrealForm($("#addForm"), form);
                this.initSubmit();
            },
            initSubmit: function () {
                $("#addButton").click(function () {
                    $("#addButton").hide();
                    $("#addButton-loading").show();
                    $("#addButton-loading").loading();
                    form.on('submit(form)', function () {
                        examPapersApi.saveForm(isNew, $('#addForm'), function () {
                            parent.window.dataReload();
                            Common.info("保存成功");
                            Lib.closeFrame();
                        });
                    });
                });

                $("#addButton-cancel").click(function () {
                    Lib.closeFrame();
                });
            }

        }
        view.init();
        <!--# if(!(isEmpty(examPapersJson))){  -->
        var formJson = ${examPapersJson};
        form.val("editform", formJson);
        $(".file_link").each(function () {
            var a = document.createElement('a');
            var aJq = $(a);
            aJq.html("下载文件");
            aJq.attr("href", formJson[$(this).attr("id")]);
            aJq.attr("target", "_blank");
            $(this).append(aJq);
        });
        <!--# } -->
    });
</script>
